package leetcode.code0234;

import leetcode.IDebug;
import leetcode.helper.tree.ListNode;

public class Solution implements IDebug {

	public boolean isPalindrome(ListNode head) {
		ListNode p = head;
		int size = 0;
		while (p != null) {
			size += 1;
			p = p.next;
		}
		int mid = size >> 1;
		p = head;
		int[] stack = new int[mid];
		int pstack = 0;
		while (mid > 0) {
			stack[pstack++] = p.val;
			p = p.next;
			mid--;
		}
		if ((size & 1) == 1) {
			p = p.next;
		}
		while (p != null) {
			if (p.val != stack[--pstack]) {
				return false;
			}
			p = p.next;
		}
		return true;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
